﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DevExpress.XtraEditors;
using System.Text.RegularExpressions;
namespace Sunboxsoft.ASMS.Client.UI.Common.Validations
{
    /// <summary>
    /// 验证邮箱格式
    /// </summary>
    public class TextEditEMailValidation : TextEditRegexValidation
    {
        /// <summary>
        /// 验证邮箱格式
        /// </summary>
        /// <param name="textEdit"></param>
        public TextEditEMailValidation(TextEdit textEdit)
            : base(textEdit, @"^([\w-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([\w-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$", "邮箱", true)
        {
        }
        public override bool ValueChanging(string newValue)
        {
            if (string.IsNullOrEmpty(newValue))
            {
                return true;
            }
            else
            {
                Regex regex = new Regex(@"^[\w\d_\@\.]*$");
                if (regex.IsMatch(newValue) && newValue.Length <= 64)
                {
                    return true;
                }
                return false;
            }
        }
    }
}
